//    Copyright (C) Kherty.  All rights reserved.
using OpenLS.Core;
using OpenLS.Spreadsheet.Internals;

namespace OpenLS.Spreadsheet.Drawing
{
    class DraggedAnchorUndoUnit : AnchorFakeCompositeUndoUnit
    {
        private double x;
        private double y;

        public DraggedAnchorUndoUnit(Anchor anchor, double x, double y): base (anchor)
        {
            this.x = x;
            this.y = y;
        }

        #region IUndoUnit Members

        public override void Do()
        {
            Anchor.Drag(-x, -y);
        }

        public override bool Merge(IUndoUnit unit)
        {
            var u = unit as DraggedAnchorUndoUnit;
            if (u != null && u.Anchor == Anchor)
            {
                x += u.x;
                y += u.y;
                return true;
            }
            return false;
        }

        #endregion

        public override string Text
        {
            get { return StringTable.Anchor; }
        }
    }
}
